<?php

/**
 * Abstract Class Driver
 * Copyright 2009 Matt Basta
 * 
 */

abstract class cloud_driver extends cloud_base {
	
	private $hasInit = false; // Should be set to true on init
	
	// Constructors and Destructors
	public function __construct($credentials) {
		// Securely stuff away our credentials
		self::secure('credentials', $credentials);
		// Initialize the database driver
		
		return $this->init();
	}
	public function __destruct() {
		return $this->close();
	}
	
	// State Functions
	abstract public function init();
	abstract public function close();
	public function hasBeenInit() {return $this->hasInit;}
	
	
	// Table functions
	abstract public function create_table($name, $columns);
	abstract public function get_table_list();
	abstract public function get_table($name);
	public function delete_table($name) {
		// Retrieve the table to delete
		$table = $this->get_table($name);
		// Destroy it
		$table->destroy();
	}
	
	
	// Security Functions
	public function escape($data) {
		switch(gettype($data)) {
			case 'integer':
				if($type != 'big')
					return self::escapeInteger($data);
			case 'float':
				return self::escapeFloat($data);
			case 'string':
				return self::escapeString($data);
			case 'object':
				switch(get_class($data)) {
					case 'simpleToken':
						return self::prepareSimpleToken($data);
					case 'logicCombinator':
						return self::prepareCombinator($data);
					case 'comparison':
						return self::prepareComparison($data);
					case 'listOrder':
						return self::prepareListOrder($data);
				}
		}
	}
	abstract public function escapeString($data);
	abstract public function escapeInteger($data);
	abstract public function escapeFloat($data); // Helps out with number padding
	
	abstract public function prepareSimpleToken($token);
	abstract public function prepareSimpleTokens($token);
	abstract public function prepareCombinator($comparison);
	abstract public function prepareComparison($comparison);
	abstract public function prepareListOrder($listorder);
	
	// Function commands
	abstract protected function supports_function($name); // Expected boolean
	
	
}